﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyATM.Entity;
using MyATM.DataAccess;
using MyATM.Bussiness;
using MyATM.Common;
using MyAtm.GUI.Properties;

namespace MyAtm.GUI
{
    public partial class AtmConsole : Form
    {
        /// <summary>
        /// Object ClientSystem
        /// </summary>
        private readonly ClientSystem clientSystem;
        /// <summary>
        /// 0 - Khong duoc nhap
        /// 1 - txtCardId
        /// 2 - txtScreen
        /// </summary>
        private int txtInput;
        /// <summary>
        /// 0 - Non function
        /// 1 - Validate card
        /// 2 - Withdraw money
        /// 3 - Change PIN
        ///  </summary>
        private int txtFunction;
        /// <summary>
        /// 
        /// </summary>
        private string newPassword;
        private string confirmPassword;
        private bool accessed;
        private Card atmCard;
        private static bool session = false;

        public AtmConsole()
        {
            InitializeComponent();
            txtInput = 1;
            txtFunction = 1;
            clientSystem = new ClientSystem();
            atmCard = new Card();
            newPassword = string.Empty;
            confirmPassword = string.Empty;
            accessed = false;
            txtScreen.ReadOnly = true;
            lblNoctic6.Hide();
        }

        private void AtmConsole_Load(object sender, EventArgs e)
        {
            label2.Text = Resources.InsertCard;
            txtCardId.Focus();
        }
        #region Keyboard
        /// <summary>
        /// Click button 1
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn1_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num1;
        }
        
        private void btn2_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num2;
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num3;
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num4;
        }

        private void btn5_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num5;
        }

        private void btn6_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num6;
        }

        private void btn7_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num7;
        }

        private void btn8_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num8;
        }

        private void btn9_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num9;
        }

        private void btn0_Click(object sender, EventArgs e)
        {
            txtCardId.Text += Resources.Num0;
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            txtCardId.Text = "";
        }
        #endregion

        /// <summary>
        /// Xu ly khi nut Enter duoc click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEnter_Click(object sender, EventArgs e)
        {
            //Valid card
            bool check = clientSystem.ValidateCard(txtCardId.Text.Trim());
            if (check)
            {
                session = true;
                txtCardId.Hide();
                txtScreen.ReadOnly = false;
                label2.Text = Resources.SessionOpen;
                ShowMenu(true);
            }
            else
            {
                session = false;
                MessageBox.Show(Resources.LoginFaill);
                txtCardId.Text = string.Empty;
            }
        }

        public void ShowMenu(bool isShowMenu)
        {
            if(isShowMenu)
            {
                lblNoctic1.Text = Resources.Withdraw;
                lblNoctic2.Text = Resources.ViewBalance;
                lblNoctic4.Text = Resources.ChangPin;
                lblNoctic5.Text = Resources.Balance;
            }
            else
            {
                lblNoctic1.Hide();
                lblNoctic2.Hide();
                lblNoctic4.Hide();
                lblNoctic5.Hide();
            }
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            session = false;
            ShowMenu(false);
            txtCardId.Show();
            txtCardId.Text = string.Empty;
        }

        private void btnSelect_1_Click(object sender, EventArgs e)
        {
            lblNoctic6.Text = Resources.Balance + " " + clientSystem.ViewBalance().ToString();
            lblNoctic6.Show();
        }
        

       

        

    }
}
